<template>
  <view>
    <text>当前计数：{{ count }}</text>
    <button @click="increment">增加</button>
    <button @click="incrementAsync">延迟增加</button>
    <button @click="fetchUserInfo">获取用户信息</button>
    <button type="default" @click="gotoTest">跳转到新页面</button>
    <view v-if="userInfo">
      <text>用户信息：{{ userInfo.name }}，{{ userInfo.age }}岁</text>
    </view>
  </view>
</template>
 
<script>
import { useStore } from 'vuex';
import { computed } from 'vue';
 
export default {
  setup() {
    const store = useStore();  // 获取 Vuex store
    const count = computed(() => store.getters.count);  // 获取 count
    const userInfo = computed(() => store.getters.userInfo);  // 获取用户信息
    
	const gotoTest = () => {
		uni.navigateTo({
			url:'/pages/index/test'
		})
	}
	
    const increment = () => {
      store.commit('increment');  // 提交 mutation
    };
 
    const incrementAsync = () => {
      store.dispatch('incrementAsync');  // 调用 action
    };
 
    const fetchUserInfo = () => {
      store.dispatch('fetchUserInfo');  // 获取用户信息
    };
	
    return {
      count,
      userInfo,
      increment,
      incrementAsync,
      fetchUserInfo,
	  gotoTest
    };
  },
};
</script>
 
<style scoped>
/* 样式略 */
</style>